## 练习 1：调用 ping 命令
#   - 编写 ping 函数  def ping(host):
#   - 用于测试远程主机的联通性  ping -c 2 127.0.0.1 &> /dev/null
#   - ping 通显示：x.x.x.x:up
#   - ping 不通显示：x.x.x.x:down
import subprocess
def ping(host):
    result = subprocess.run(
        "ping -c 2 " + host + " &> /dev/null",
        shell=True
    )
    if result.returncode == 0:
        print(host + ":up")
    else:
        print(host + ":down")
ping("www.baidu.com")
